package com.haiyou.dc.es.controller;

import com.google.common.collect.Lists;
import com.haiyou.dc.es.bi.impl.EsRentHouseService;
import com.haiyou.dc.es.constant.EsConstant;
import com.haiyou.dc.es.constant.RentValueBlock;
import com.haiyou.dc.es.entity.EsSupportAddress;
import com.haiyou.dc.es.entity.form.RentSearchForm;
import com.haiyou.dc.es.service.EsSupportAddressService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author root
 * @date 2020-01-20 16:11:34
 */
@Controller
@RequestMapping("/esRentHouse")
@Slf4j
@Api(tags = "房屋租房信息表")
public class EsRentHouseController {

    @Autowired
    private EsSupportAddressService esSupportAddressService;
    @Autowired
    private EsRentHouseService esRentHouseService;

    @GetMapping("rent/house")
    public String rentHousePage(@ModelAttribute RentSearchForm rentSearch
            , Model model) {
//        if (rentSearch.getCityEnName() == null) {
//            rentSearch.setCityEnName("bj");
//        }
//        if (rentSearch.getRegionEnName() == null) {
//            rentSearch.setRegionEnName("*");
//        }
//
//        model.addAttribute("searchBody", rentSearch);


//        EsSupportAddress esSupportCityAddress = esSupportAddressService.selectOne(new EsSupportAddress()
//                .setEnName(rentSearch.getCityEnName())
//                .setLevel(EsConstant.Level.CITY.getValue()));
//        model.addAttribute("currentCity", esSupportCityAddress);
//
//        EsSupportAddress esSupportRegionAddress = esSupportAddressService.selectOne(new EsSupportAddress()
//                .setEnName(rentSearch.getCityEnName())
//                .setLevel(EsConstant.Level.REGION.getValue()));
//
//        List<EsSupportAddress> addressList = esSupportAddressService.select(new EsSupportAddress()
//                .setLevel(EsConstant.Level.REGION.getValue())
//                .setBelongTo(rentSearch.getCityEnName()));
//        model.addAttribute("regions", addressList);




        model.addAttribute("priceBlocks", RentValueBlock.PRICE_BLOCK);
        model.addAttribute("areaBlocks", RentValueBlock.AREA_BLOCK);

        model.addAttribute("total", 0);
        model.addAttribute("houses", Lists.newArrayList());

        return "rent-list";
    }
}